/*##############################################################################

	Name	: ATTINY26 Motor driver - I2C via USI-TWI, TB6612FNG
	Version	: 0.1  - alpha
	autor	: Odo Maletzki odo@maletzki.net
	page	: www.maletzki.net
	License	: GNU General Public License 


    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details

//############################################################################*/


#include 	<stdlib.h>
#include 	<avr/io.h>
#include 	<avr/interrupt.h>
#include 	<avr/pgmspace.h>

#include "usi-twi-slave.h"
#include "motdrv.h"     		


// Note: The LSB is the I2C r/w flag and must not be used for addressing!

#define 	SLAVE_ADDR_ATTINY       0x30

#ifndef 	F_CPU
#define 	F_CPU 8000000UL
#endif





int main(void)
{	

	motor_init();

	spdMotA = 0x00;
	spdMotB = 0x00;
	MOTOR_PORT = (MOTOR_PORT & 0xF0) | (0x00 & 0x0F);
	motorActivate();
	
	ADC_init();
	
	cli();  // Disable interrupts
	
	
	USI_init(SLAVE_ADDR_ATTINY);	// TWI slave init
	
	sei();  // Re-enable interrupts

	while(1)
    {
//		if ( MOTOR_PIN & (1 << BTN_PIN) ) {
//			CTRL_DEBUG_1_ON();
//		}
//		else {
//			CTRL_DEBUG_1_OFF();
//		}
		
//		adc_result = ADCH;
	;	

	} 

} 



